﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        Int32 State, Action;
        Double operand1, operand2, result;
        public Form1()
        {
            InitializeComponent();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text += "2";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (State == 1)
            {
                State = 2;
                Action = 4;
                textBox1.Text = "";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text += "9";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text += "8";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (State == 1)
            {
                State = 2;
                Action = 3;
                textBox1.Text = "";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text += "7";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text += "6";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text += "5";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text += "4";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (State == 1)
            {
                State = 2;
                Action = 2;
                textBox1.Text = "";
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text += "3";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text += "1";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (State == 1)
            {
                State = 2;
                Action = 1;
                textBox1.Text = "";
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button14_Click(object sender, EventArgs e)
        {
            State = 1;
            textBox1.Text = "";
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (State == 2)
            {
                State = 1;
                if (Action == 1) result = operand1 + operand2;
                if (Action == 2) result = operand1 - operand2;
                if (Action == 3) result = operand1 * operand2;
                if (Action == 4) result = operand1 / operand2;
                textBox1.Text = System.Convert.ToString(result);
                operand1 = result;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            State = 1;
            textBox1.Text = "";
        }

        private void button16_Click(object sender, EventArgs e)
        {
            textBox1.Text += "0";
            if (State == 1) operand1 = Convert.ToDouble(textBox1.Text);
            if (State == 2) operand2 = Convert.ToDouble(textBox1.Text);
        }
    }
}
